import { createBrowserRouter, Navigate } from 'react-router-dom';
import Login from '../view/Login/login';
import Home from '../view/Home/index';
import Layout from '../view/Layout/index';
// import Hiresphere from '../view/Hiresphere/index';
import Resume from '../view/User/Resume/Resume';
import Notice from '../view/Help/Notice/index';
import Guide from '../view/Help/Guide/index';
import Agreement from '../view/Help/Agreement/index';
import Analyse from '../view/User/Analyse/index';
import Hiresphere from '@/view/Hiresphere/MockInterview';
import AiInterview from '@/view/Hiresphere/AiInterview';
import Hoist from '@/view/User/Hoist';
const isAuthenticated = () => {
  return localStorage.getItem('token') !== null;
};

const PrivateRoute = ({ element }: { element: JSX.Element }) => {
  return isAuthenticated() ? element : <Navigate to="/login" />;
};

const routers = [
  {
    path: '/',
    element: (
      <Layout>
        <PrivateRoute element={<AiInterview />} />
      </Layout>
    ),
  },
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/hire-sphere',
    element: (
      <Layout>
        <PrivateRoute element={<Hiresphere />} />
      </Layout>
    ),
  },
  {
    path: '/ai-interview',
    element: (
      <Layout>
        <PrivateRoute element={<AiInterview />} />
      </Layout>
    ),
  },
  {
    path: '/home',
    element: (
      <Layout>
        <PrivateRoute element={<Home />} />
      </Layout>
    ),
  },
  {
    path: '/user',
    children: [
      {
        path: '/user/resume',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Resume />
              </Layout>
            }
          />
        ),
      },
      {
        path: '/user/analyse',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Analyse />
              </Layout>
            }
          />
        ),
      },
      {
        path: '/user/hoist',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Hoist />
              </Layout>
            }
          />
        ),
      },
    ],
  },
  {
    path: '/help',
    children: [
      {
        path: '/help/notice',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Notice />
              </Layout>
            }
          />
        ),
      },
      {
        path: '/help/guide',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Guide />
              </Layout>
            }
          />
        ),
      },
      {
        path: '/help/agreement',
        element: (
          <PrivateRoute
            element={
              <Layout>
                <Agreement />
              </Layout>
            }
          />
        ),
      },
    ],
  },
];

// eslint-disable-next-line react-refresh/only-export-components
export default createBrowserRouter(routers, {
  future: {
    // v7_skipActionErrorRevalidation is not a known property, removing it
  },
});
